<!--  -->
<template>
    <div class=''>
        <!-- 面包屑导航区，图标分隔符 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{path:'/home'}">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
            </el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片视图区 -->
        <el-card>
            <!-- 搜索区 -->
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容" v-model="queryInfo.query">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>

            <!-- 订单列表数据 -->
            <el-table :data="orderList" border stripe>
                <!-- 索引列 -->
                <el-table-column label="#" type="index"></el-table-column>
                <el-table-column label="订单编号" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price"></el-table-column>
                <el-table-column label="是否付款" prop="pay_status">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.pay_status==='1'">已付款</el-tag>
                        <el-tag type="danger" v-else="scope.row.pay_status==='0'">未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send">
                    <template slot-scope="scope">
                        {{scope.row.is_send}}
                    </template>
                </el-table-column>
                <el-table-column label="下单时间" prop="create_time">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dataFormat}}
                    </template>
                </el-table-column>

                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" icon="el-icon-edit" @click="showBox">修改地址</el-button>
                        <el-button type="success" size="mini" icon="el-icon-location" @click="showProgressBox">物流进度
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>

        <!-- 分页 -->
        <el-pagination :total="total" :current-page="queryInfo.pagenum" :page-size="queryInfo.pagesize"
            @current-change="handelCurrentChange" @size-change="handelSizeChange" :page-sizes="[5,10,15,20]"
            layout="total,sizes,prev,pager,next,jumper"></el-pagination>

        <!-- 修改地址对话框 -->
        <el-dialog title="修改地址" :visible.sync="addressVisible" width="50%" @close="handleClose">

            <el-form :model="addressForm" :rules="addressRules" ref="addressForm" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <!-- v-model指定当前选中的值 -->
                    <!-- option指定数据源 -->
                    <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
                </el-form-item>

                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>

            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="addressVisible=false">取消</el-button>
                <el-button type="primary">确定</el-button>
            </span>
        </el-dialog>

        <!-- 展示物流进度对话框 -->
        <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
                <span>扣税的韩国空军和</span>
        </el-dialog>
    </div>
</template>

<script>
    //这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
    //例如：import 《组件名称》 from '《组件路径》';
    import citydata from '@/components/order/citydata'//导入省市联动数据

    export default {
        //import引入的组件需要注入到对象中才能使用
        name: 'Order',
        components: {},
        props: {},
        data() {
            //这里存放数据
            return {
                //查询对象
                queryInfo: {
                    query: '',//查询关键词
                    pagenum: 1,
                    pagesize: 5,
                },
                total: 0,//数据总数
                orderList: [],//订单数据
                addressVisible: false,//控制修改地址对话框显示隐藏
                addressForm: {
                    address1: [],
                    address2: '',
                },//
                addressRules: {
                    address1: [
                        { required: true, message: '请选择省市区县', trigger: 'blur' }
                    ],
                    address2: [{ required: true, message: '请填写详细地址', trigger: 'blur' }],
                },//
                cityData: citydata,//省市联动数据
                progressVisible:false,//控制物流进度对话框显示隐藏
                progressInfo:[],//物流信息数据
            };
        },
        //监听属性 类似于data概念
        computed: {},
        //监控data中的数据变化
        watch: {},
        //方法集合
        methods: {
            //获取所有订单数据
            async getOrderList() {
                const { data: res } = await this.$http.get('orders', { params: this.queryInfo });
                if (res.meta.status !== 200) return this.$message.error(res.meat.msg);
                // console.log(res);
                this.total = res.data.total
                this.orderList = res.data.goods;
            },

            //监听当前页码改变触发的函数
            handelCurrentChange(newPage) {
                this.queryInfo.pagenum = newPage
                this.getOrderList();//刷新数据
            },

            //监听每页显示多少条数据改变触发的函数
            handelSizeChange(newSize) {
                this.queryInfo.pagesize = newSize;
                this.getOrderList();
            },

            //显示修改地址对话框
            showBox() {
                this.addressVisible = true;
            },
            //监听关闭修改地址对话框方法
            handleClose() {
                this.$refs.addressForm.resetFields();
                this.addressVisible = false;
            },

            //显示物流进度对话框
            async showProgressBox() {
                const { data: res } = await this.$http.get('kuaidi/1106975712662');
                console.log(res);
                if (res.meta.status !== 200) return this.$message.error(res.meat.msg);
                this.progressInfo=res.data;
                console.log(this.progressInfo);
                this.progressVisible=true;
            }
        },
        //生命周期 - 创建完成（可以访问当前this实例）
        created() {
            this.getOrderList();//获取所有订单数据
        },
        //生命周期 - 挂载完成（可以访问DOM元素）
        mounted() {

        },
        beforeCreate() { }, //生命周期 - 创建之前
        beforeMount() { }, //生命周期 - 挂载之前
        beforeUpdate() { }, //生命周期 - 更新之前
        updated() { }, //生命周期 - 更新之后
        beforeDestroy() { }, //生命周期 - 销毁之前
        destroyed() { }, //生命周期 - 销毁完成
        activated() { }, //如果页面有keep-alive缓存功能，这个函数会触发
    }
</script>
<style scoped lang='scss'>
    .el-cascader {
        width: 100%;
    }
</style>